<h1 id="ftp">ftp</h1>
<p>用来设置文件系统相关功能</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>ftp命令</strong> 用来设置文件系统相关功能。ftp服务器在网上较为常见，Linux ftp命令的功能是用命令的方式来控制在本地机和远程机之间传送文件，这里详细介绍Linux ftp命令的一些经常使用的命令，相信掌握了这些使用Linux进行ftp操作将会非常容易。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">ftp(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-d：详细显示指令执行过程，便于排错或分析程序执行的情况；
-i：关闭互动模式，不询问任何问题；
-g：关闭本地主机文件名称支持特殊字符的扩充特性；
-n：不使用自动登录；
-v：显示指令执行过程。</code></pre>
<h3 id="参数">参数</h3>
<p>主机：指定要连接的FTP服务器的主机名或ip地址。</p>
<h3 id="实例">实例</h3>
<div class="sourceCode" id="cb3"><pre><code class="language-bash"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="fu">ftp</span><span class="op">&gt;</span> ascii  # 设定以ASCII方式传送文件(缺省值) </a>
<a class="sourceLine" id="cb3-2" data-line-number="2"><span class="fu">ftp</span><span class="op">&gt;</span> bell   # 每完成一次文件传送,报警提示. </a>
<a class="sourceLine" id="cb3-3" data-line-number="3"><span class="fu">ftp</span><span class="op">&gt;</span> binary <span class="co"># 设定以二进制方式传送文件. </span></a>
<a class="sourceLine" id="cb3-4" data-line-number="4"><span class="fu">ftp</span><span class="op">&gt;</span> bye    # 终止主机FTP进程,并退出FTP管理方式. </a>
<a class="sourceLine" id="cb3-5" data-line-number="5"><span class="fu">ftp</span><span class="op">&gt;</span> case   # 当为ON时,用MGET命令拷贝的文件名到本地机器中,全部转换为小写字母. </a>
<a class="sourceLine" id="cb3-6" data-line-number="6"><span class="fu">ftp</span><span class="op">&gt;</span> cd     # 同UNIX的CD命令. </a>
<a class="sourceLine" id="cb3-7" data-line-number="7"><span class="fu">ftp</span><span class="op">&gt;</span> cdup   # 返回上一级目录. </a>
<a class="sourceLine" id="cb3-8" data-line-number="8"><span class="fu">ftp</span><span class="op">&gt;</span> chmod  # 改变远端主机的文件权限. </a>
<a class="sourceLine" id="cb3-9" data-line-number="9"><span class="fu">ftp</span><span class="op">&gt;</span> close  # 终止远端的FTP进程,返回到FTP命令状态, 所有的宏定义都被删除. </a>
<a class="sourceLine" id="cb3-10" data-line-number="10"><span class="fu">ftp</span><span class="op">&gt;</span> delete <span class="co"># 删除远端主机中的文件. </span></a>
<a class="sourceLine" id="cb3-11" data-line-number="11"><span class="fu">ftp</span><span class="op">&gt;</span> dir [remote-directory] [local-file] <span class="co"># 列出当前远端主机目录中的文件.如果有本地文件,就将结果写至本地文件. </span></a>
<a class="sourceLine" id="cb3-12" data-line-number="12"><span class="fu">ftp</span><span class="op">&gt;</span> get [remote-file] [local-file] <span class="co"># 从远端主机中传送至本地主机中. </span></a>
<a class="sourceLine" id="cb3-13" data-line-number="13"><span class="fu">ftp</span><span class="op">&gt;</span> help [command] <span class="co"># 输出命令的解释. </span></a>
<a class="sourceLine" id="cb3-14" data-line-number="14"><span class="fu">ftp</span><span class="op">&gt;</span> lcd <span class="co"># 改变当前本地主机的工作目录,如果缺省,就转到当前用户的HOME目录. </span></a>
<a class="sourceLine" id="cb3-15" data-line-number="15"><span class="fu">ftp</span><span class="op">&gt;</span> ls [remote-directory] [local-file] <span class="co"># 同DIR. </span></a>
<a class="sourceLine" id="cb3-16" data-line-number="16"><span class="fu">ftp</span><span class="op">&gt;</span> macdef                 # 定义宏命令. </a>
<a class="sourceLine" id="cb3-17" data-line-number="17"><span class="fu">ftp</span><span class="op">&gt;</span> mdelete [remote-files] <span class="co"># 删除一批文件. </span></a>
<a class="sourceLine" id="cb3-18" data-line-number="18"><span class="fu">ftp</span><span class="op">&gt;</span> mget [remote-files]    # 从远端主机接收一批文件至本地主机. </a>
<a class="sourceLine" id="cb3-19" data-line-number="19"><span class="fu">ftp</span><span class="op">&gt;</span> mkdir directory-name   # 在远端主机中建立目录. </a>
<a class="sourceLine" id="cb3-20" data-line-number="20"><span class="fu">ftp</span><span class="op">&gt;</span> mput local-files <span class="co"># 将本地主机中一批文件传送至远端主机. </span></a>
<a class="sourceLine" id="cb3-21" data-line-number="21"><span class="fu">ftp</span><span class="op">&gt;</span> open host [port] <span class="co"># 重新建立一个新的连接. </span></a>
<a class="sourceLine" id="cb3-22" data-line-number="22"><span class="fu">ftp</span><span class="op">&gt;</span> prompt           # 交互提示模式. </a>
<a class="sourceLine" id="cb3-23" data-line-number="23"><span class="fu">ftp</span><span class="op">&gt;</span> put local-file [remote-file] <span class="co"># 将本地一个文件传送至远端主机中. </span></a>
<a class="sourceLine" id="cb3-24" data-line-number="24"><span class="fu">ftp</span><span class="op">&gt;</span> pwd  # 列出当前远端主机目录. </a>
<a class="sourceLine" id="cb3-25" data-line-number="25"><span class="fu">ftp</span><span class="op">&gt;</span> quit <span class="co"># 同BYE. </span></a>
<a class="sourceLine" id="cb3-26" data-line-number="26"><span class="fu">ftp</span><span class="op">&gt;</span> recv remote-file [local-file] <span class="co"># 同GET. </span></a>
<a class="sourceLine" id="cb3-27" data-line-number="27"><span class="fu">ftp</span><span class="op">&gt;</span> rename [from] [to]     # 改变远端主机中的文件名. </a>
<a class="sourceLine" id="cb3-28" data-line-number="28"><span class="fu">ftp</span><span class="op">&gt;</span> rmdir directory-name   # 删除远端主机中的目录. </a>
<a class="sourceLine" id="cb3-29" data-line-number="29"><span class="fu">ftp</span><span class="op">&gt;</span> send local-file [remote-file] <span class="co"># 同PUT. </span></a>
<a class="sourceLine" id="cb3-30" data-line-number="30"><span class="fu">ftp</span><span class="op">&gt;</span> status   # 显示当前FTP的状态. </a>
<a class="sourceLine" id="cb3-31" data-line-number="31"><span class="fu">ftp</span><span class="op">&gt;</span> system   # 显示远端主机系统类型. </a>
<a class="sourceLine" id="cb3-32" data-line-number="32"><span class="fu">ftp</span><span class="op">&gt;</span> user user-name [password] [account] <span class="co"># 重新以别的用户名登录远端主机. </span></a>
<a class="sourceLine" id="cb3-33" data-line-number="33"><span class="fu">ftp</span><span class="op">&gt;</span> ? [command] <span class="co"># 同HELP. [command]指定需要帮助的命令名称。如果没有指定 command，ftp 将显示全部命令的列表。</span></a>
<a class="sourceLine" id="cb3-34" data-line-number="34"><span class="fu">ftp</span><span class="op">&gt;</span> ! <span class="co"># 从 ftp 子系统退出到外壳。</span></a></code></pre></div>
<p>关闭FTP连接</p>
<div class="sourceCode" id="cb4"><pre><code class="language-bash"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="ex">bye</span></a>
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="bu">exit</span></a>
<a class="sourceLine" id="cb4-3" data-line-number="3"><span class="ex">quit</span></a></code></pre></div>
<p>下载文件</p>
<div class="sourceCode" id="cb5"><pre><code class="language-bash"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="fu">ftp</span><span class="op">&gt;</span> get readme.txt <span class="co"># 下载 readme.txt 文件</span></a>
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="fu">ftp</span><span class="op">&gt;</span> mget *.txt     # 下载 </a></code></pre></div>
<p>上传文件</p>
<div class="sourceCode" id="cb6"><pre><code class="language-bash"><a class="sourceLine" id="cb6-1" data-line-number="1"><span class="fu">ftp</span><span class="op">&gt;</span> put /path/readme.txt <span class="co"># 上传 readme.txt 文件</span></a>
<a class="sourceLine" id="cb6-2" data-line-number="2"><span class="fu">ftp</span><span class="op">&gt;</span> mput *.txt           # 可以上传多个文件</a></code></pre></div>
<!-- Linux命令行搜索引擎：https://jaywcjlove.github.io/linux-command/ -->
